﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
using Contracts;
using System.Data.Linq;

namespace Radar {


    [DataContract]
    [Table(Name = "Capture")]
    public class Capture : ICapture {

        [DataMember(IsRequired = true)]
        [Column(Name = "id", IsPrimaryKey = true, IsDbGenerated = true)]
        public int id;
        [DataMember(IsRequired = true)]
        [Column(Name = "type", DbType = "varchar(250)")]
        public string type;
        [DataMember(IsRequired = true)]
        [Column(Name = "Instant", DbType = "DateTime")]
        public DateTime date;
        [DataMember(IsRequired = true)]
        [Column(Name = "speed", DbType = "real")]
        public float speed;
        [DataMember(IsRequired = true)]
        [Column(Name = "plate", DbType = "varchar(250)")]
        public string plate;

        public Capture() { }

        public Capture(string type, float speed, string plate) {
            this.type = type;
            this.speed = speed;
            this.plate = plate;
            date = DateTime.Now;
        }

        public int GetId() { return id; }
        public void SetId(int id) { this.id = id; }
        public DateTime GetDate() { return date; }
        public string GetVehicleType() { return type; }
        public float GetSpeed() { return speed; }
        public string GetPlate() { return plate; }

        public override string ToString() {
            return "Id: " + id + " | Date: " + date + " | Type: " + type + " | Speed: " + speed + " | Plate: " + plate;
        }
    }

    [DataContract]
    [Table(Name = "Image")]
    public class Image : IImage {

        [DataMember(IsRequired = true)]
        [Column(Name = "id", IsPrimaryKey = true, IsDbGenerated = true)]
        public int id;
        [DataMember(IsRequired = true)]
        [Column(Name = "captureId")]
        public int captureId;
        [DataMember(IsRequired = true)]
        [Column(Name = "image", DbType="varBinary(max)")]
        public byte[] image;

        public Image() { }

        public Image(int id, byte[] image) {
            captureId = id;
            this.image = image;
        }

        public int GetCaptureId() { return captureId; }
        public byte[] GetPicture() { return image; }
    }
}